package cn.itsource.ymcc.controller;

import cn.itsource.ymcc.dto.CourseDocumentDto;
import cn.itsource.ymcc.dto.CourseListQueryDto;
import cn.itsource.ymcc.repostory.ICourseRepository;
import cn.itsource.ymcc.result.JSONResult;
import cn.itsource.ymcc.service.ICourseService;
import cn.itsource.ymcc.vo.CourseListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchContrller {

    @Autowired
    private ICourseRepository courseRepository;

    @Autowired
    private ICourseService courseService;


    @RequestMapping("/courseOnline")
    public JSONResult courseOnline(@RequestBody CourseDocumentDto courseDocumentDto) {

        courseRepository.save(courseDocumentDto);
        return JSONResult.success();
    }


    /**
     * 查询课程列表
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/course", method = RequestMethod.POST)
    public JSONResult course(@RequestBody @Valid CourseListQueryDto courseListQueryDto) {

        CourseListVO coursevo = courseService.course(courseListQueryDto);

        return JSONResult.success(coursevo);
    }
}
